/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import entity.Events;
import entity.Users;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Jov
 */
@Entity
@Table(name = "invitations")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Invitations.findAll", query = "SELECT i FROM Invitations i"),
    @NamedQuery(name = "Invitations.findByInvitationId", query = "SELECT i FROM Invitations i WHERE i.invitationId = :invitationId"),
    @NamedQuery(name = "Invitations.findByAccepted", query = "SELECT i FROM Invitations i WHERE i.accepted = :accepted"),
    @NamedQuery(name = "Invitations.findByAnswered", query = "SELECT i FROM Invitations i WHERE i.answered = :answer"),
    @NamedQuery(name = "Invitations.findByReceiver", query = "SELECT i FROM Invitations i WHERE i.receiver = :receiver AND i.answered = false")})
public class Invitations implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "invitationId")
    private Collection<Participants> participantsCollection;
    @Column(name = "answered")
    private Boolean answered;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "invitation_id")
    private Integer invitationId;
    @Column(name = "accepted")
    private Boolean accepted;
    @JoinColumn(name = "receiver", referencedColumnName = "user_id")
    @ManyToOne
    private Users receiver;
    @JoinColumn(name = "sender", referencedColumnName = "user_id")
    @ManyToOne
    private Users sender;
    @JoinColumn(name = "event", referencedColumnName = "event_id")
    @ManyToOne
    private Events event;

    public Invitations() {
    }

    public Invitations(Integer invitationId) {
        this.invitationId = invitationId;
    }

    public Integer getInvitationId() {
        return invitationId;
    }

    public void setInvitationId(Integer invitationId) {
        this.invitationId = invitationId;
    }

    public Boolean getAccepted() {
        return accepted;
    }

    public void setAccepted(Boolean accepted) {
        this.accepted = accepted;
    }

    public Users getReceiver() {
        return receiver;
    }

    public void setReceiver(Users receiver) {
        this.receiver = receiver;
    }

    public Users getSender() {
        return sender;
    }

    public void setSender(Users sender) {
        this.sender = sender;
    }

    public Events getEvent() {
        return event;
    }

    public void setEvent(Events event) {
        this.event = event;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (invitationId != null ? invitationId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Invitations)) {
            return false;
        }
        Invitations other = (Invitations) object;
        if ((this.invitationId == null && other.invitationId != null) || (this.invitationId != null && !this.invitationId.equals(other.invitationId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entityP.Invitations[ invitationId=" + invitationId + " ]";
    }

    public Boolean getAnswered() {
        return answered;
    }

    public void setAnswered(Boolean answered) {
        this.answered = answered;
    }

    @XmlTransient
    public Collection<Participants> getParticipantsCollection() {
        return participantsCollection;
    }

    public void setParticipantsCollection(Collection<Participants> participantsCollection) {
        this.participantsCollection = participantsCollection;
    }
    
}
